package com.wlc.rabbitmq;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 生产者
 *
 * @author milicool
 * Created on 2018/9/14
 */
@Component
public class Producer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 100
     **/
    private static final int total = 5;


    /**
     * 给hello队列发送消息
     */
    public void send() {
        try {
            for (int i = 0; i < total; i++) {
                String msg = "hello, 序号: " + i;
                System.out.println("Producer, " + msg);
                rabbitTemplate.convertAndSend("queue-test", msg);
                rabbitTemplate.convertAndSend("work_queue", msg);
                //rabbitTemplate.convertAndSend("queue-test2", msg);
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }



}